<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>菜鸟教程</title>
  </head>
  <body>
    <script type="text/javascript">
      console.log("递归函数演示");
      function factorial(n) {
        let result = 1;
        for (let i = 1; i <= n; i++) {
          result = result * i;
        }
        return result;
      }
      console.log(factorial(5));

      function fac2(n) {
        if (n == 1) {
          return 1;
        }
        return n * fac2(n - 1);
      }
      console.log(fac2(5));
    </script>
  </body>
</html>
